package LEETCODE2023.BISHUA100;

import java.util.ArrayList;
import java.util.List;

/**
 * 中序遍历，递归用法
 */
public class SolutionBM24 {
    public int[] inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        sum(root, list);
        int[] num = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            num[i] = list.get(i);
        }
        return num;
    }

    public void sum(TreeNode node, List<Integer> list) {
        if (node == null) {
            return;
        }
        sum(node.left, list);
        list.add(node.val);
        sum(node.right, list);
    }
}
